package com.ys.controller.api.outer;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bo.dto.NameValueDto;
import com.bo.util.DateUtil;
import com.ys.config.MyConfig;
import com.ys.constant.AppConstant;
import com.ys.dto.OptionDto;
import com.ys.entity.amazonorder.TcoDayShop;
import com.ys.entity.storage.TccAllocate;
import com.ys.entity.storage.TccAllocateDetail;
import com.ys.entity.storage.TccDistributeDetail;
import com.ys.entity.storage.TccStockControl;
import com.ys.entity.sys.TbStaticConfig;
import com.ys.entity.sys.TsOrganizationInfo;
import com.ys.entity.sys.YsDict;
import com.ys.entity.sys.YsMenu;
import com.ys.entity.sys.YsModalSelector;
import com.ys.entity.sys.YsModalSelectorField;
import com.ys.enume.storage.TccAllocateEnum;
import com.ys.enume.storage.TccStockFrozenRunningEnum;
import com.ys.enume.storage.TccStockSourceEnum;
import com.ys.mapper.business.DiySqlMapper;
import com.ys.mapper.storage.StorageMapper;
import com.ys.mapper.sys.YsMenuMapper;
import com.ys.service.amazonorder.TcoDayShopService;
import com.ys.service.amazonorder.TpAmazonShopOrderDailyService;
import com.ys.service.business.TcwAccountDetailedForCompanyService;
import com.ys.service.business.TpAmazonShopService;
import com.ys.service.finance.TcwAccountCountForCompanyService;
import com.ys.service.finance.TcwWanliPayoutService;
import com.ys.service.storage.TccDistributeService;
import com.ys.service.storage.TccStockControlService;
import com.ys.service.sys.TsFilesInfoService;
import com.ys.service.sys.TsOrganizationInfoService;
import com.ys.service.sys.YsSynService.ModalConfigDto;
import com.ys.util.TxtUtil;

@Controller
@RequestMapping("/api/outer/demoXDH")
public class ApiOuterDemoXDHController {
	@Autowired
	private YsMenuMapper ysMenuMapper;
	@Autowired
	private DiySqlMapper diySqlMapper;
    
    @Autowired
    private TpAmazonShopOrderDailyService tpAmazonShopOrderDailyService;
    
    @Autowired
    private TcoDayShopService tcoDayShopService;
    
    @Autowired
    private TpAmazonShopService tpAmazonShopService;
    
    @Autowired
    private TsOrganizationInfoService tsOrganizationInfoService;
    
    @Autowired
    private TcwWanliPayoutService tcwWanliPayoutService;
	@Autowired
	private TccDistributeService tccDistributeService;
	@Autowired
	private TccStockControlService tccStockControlService;
	@Autowired
	private TcwAccountCountForCompanyService tcwAccountCountForCompanyService;
	@Autowired
	private TcwAccountDetailedForCompanyService tcwAccountDetailedForCompanyService;
	@Autowired
	private StorageMapper storageMapper;
	
    @RequestMapping("/test")
	@ResponseBody
	public void test(Long id) {
    	try {
    		TccDistributeDetail detail = new TccDistributeDetail().setId(id).queryFirst();
			TccAllocateDetail tccAllocateDetail = new TccAllocateDetail().setId(detail.getAllocateDetailId()).queryFirst();
			String productCode = tccAllocateDetail.getProductCode();

			
			// 变更预约调拨单分配状态
			storageMapper.updateStateDistributeOfTccAllocateDetail(tccAllocateDetail.getId());
			
			// 调出方库存解冻并出库
			{
				Long stockControlId = detail.getStockControlId();
				Integer num = detail.getNum();
				Integer sourceType = TccStockFrozenRunningEnum.SourceType.TCC_Distribute_FLOW_FINISH.value;
				String sourceBid = detail.getBidDistribute();
				Long sourceId = detail.getId();
				tccStockControlService.thaw(stockControlId, num, sourceType, sourceBid, sourceId);
			}
			{
				Long stockControlId = detail.getStockControlId();
				String remark = "手工分配单：" + detail.getBidDistribute();
				Integer numOut = detail.getNum();
				String bidRelative = detail.getBidDistribute();
				Integer sourceType = TccStockSourceEnum.Source.TCC_Distribute.value;
				tccStockControlService.outWithRunning(stockControlId, remark, numOut, bidRelative, sourceType,tccAllocateDetail.getId());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
